<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>套餐设置</title>
<link rel="shortcut icon" href="${pageContext.request.contextPath }/bootstrapStyle/img/favicon.ico">
<link href="${pageContext.request.contextPath }/bootstrapStyle/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
<link href="${pageContext.request.contextPath}/bootstrapStyle/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrapStyle/css/style.min.css?v=4.0.0" rel="stylesheet">
<link href="${pageContext.request.contextPath }/bootstrap/css/jquery-confirm.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/bootstrapStyle/css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content">
    	<c:if test="${packageDetail!= null}">
    		<div class="col-sm-12">
	        	<div class="ibox float-e-margins">
	        		<a class="btn btn-w-m btn-default " href="${pageContext.request.contextPath }/Main/packageMan/packageList.action"><i class="fa fa-chevron-left"></i> 返回列表</a>
	        	</div>
        	</div>
    	</c:if>
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>设置医疗套餐</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="alert alert-info">
                        	 根据自定义的医疗套餐，设置每个医疗套餐，包括套餐名称，套餐数额以及套餐详情
                        </div>
                        <form role="form" class="form-horizontal m-t">
                            <div class="form-group draggable">
                                <label class="col-sm-1 control-label">套餐名称：</label>
                                <div class="col-sm-6">
                                    <input type="text" name="packagename" id="packagename" value="${packageDetail.packagename}" minlength="5" maxlength="20" class="form-control" placeholder="请输入套餐名，字数5-20" required="" aria-required="true">
                                </div>
                            </div>
                            <div class="form-group draggable">
                                <label class="col-sm-1 control-label">套餐数额：</label>
                                <div class="col-sm-6">
                                    <input type="text" onkeyup="num(this)" value="${packageDetail.packagenumber}" name="packagenumber" id="packagenumber"  class="form-control" placeholder="请输入套餐数额，数额大于零" required="" aria-required="true">
                                </div>
                            </div>
                            <div class="form-group draggable">
                                <label class="col-sm-1 control-label">套餐持续时长：</label>
                                <div class="col-sm-5">
                                    <input type="text" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"  
    onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}" value="${packageDetail.packagesustime}" name="packagesustime" id="packagesustime"  class="form-control" placeholder="套餐持续时间，单位为（天）" required="" aria-required="true">
                                </div>
                                <label class="col-sm-1 control-label">天</label>
                            </div>
                            <div class="form-group draggable">
                                <label class="col-sm-1 control-label">套餐操作时间：</label>
                                <div class="col-sm-6">
                                    <input type="text" name="packageoperatetime" id="packageoperatetime" value="${packageDetail.packageoperatetime}" minlength="5" maxlength="20" class="form-control" placeholder="描述套餐操作时间，如几月几日星期几上午几点，字数5-20" required="" aria-required="true">
                                </div>
                            </div>
                            <%-- <div class="form-group draggable">
                                <label class="col-sm-1 control-label">开始时间：</label>
                                <div class="col-sm-4 input-group date" id="datetimepicker1">  
					                <input type='text' class="form-control" name="packagestime" id="packagestime" value="<fmt:formatDate value="${packageDetail.packagestime}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>  
					                <span class="input-group-addon">  
					                    <span class="glyphicon glyphicon-calendar"></span>  
					                </span>  
					            </div>
					        </div>
					        <div class="form-group draggable">
                                <label class="col-sm-1 control-label">结束时间：</label>
                                <div class="col-sm-4 input-group date" id="datetimepicker2">  
					                <input type='text' class="form-control" name="packageetime" id="packageetime" value="<fmt:formatDate value="${packageDetail.packageetime}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>  
					                <span class="input-group-addon">  
					                    <span class="glyphicon glyphicon-calendar"></span>  
					                </span>  
					            </div>
                            </div> --%>
                            <div class="form-group draggable">
                                <label class="col-sm-1 control-label">套餐详情：</label>
                                <div class="col-sm-6">
                                    <textarea name="packageabs" onkeyup="words_deal('packageabs');" id="packageabs" rows="6" minlength="10" maxlength="150" class="form-control" placeholder="请输入套餐详情,字数在10-150" required="" aria-required="true">${packageDetail.packageabs}</textarea>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group draggable">
                                <div class="col-sm-12 col-sm-offset-6">
                                    <button class="btn btn-primary" style="width:80px;" type="button" onclick="packageSubmit(${packageDetail.packageid});" id="SaveSubmit">保存</button>
                                    <button class="btn btn-white" style="width:80px;" type="reset">重置</button>
                                </div>
                            </div>
                        </form>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="${pageContext.request.contextPath }/bootstrapStyle/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath }/bootstrapStyle/js/jquery-1.8.3.min.js"></script>
    <script src="${pageContext.request.contextPath }/bootstrapStyle/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath }/bootstrapStyle/js/jquery-confirm.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/bootstrapStyle/js/bootstrap-datetimepicker.js" charset="UTF-8"></script>
    <script type="text/javascript">
    	function packageSubmit(packageid){
    		//$.alert(''+unitpriceid);
    		var packagename = $('#packagename').val();
    		var packagenumber = $('#packagenumber').val();
    		var packageabs = $('#packageabs').val();
    		var packagesustime = $('#packagesustime').val();
    		var packageoperatetime = $('#packageoperatetime').val();
    		
    		if(!packagename || !packagenumber || !packageabs || !packagesustime || !packageoperatetime){
    			/* $.alert({
        		    title: '提示!',
        		    content: '内容不可为空',
        		    type: 'red',
        		    typeAnimated: true,
        		    buttons:{确定:function(){}}
        		}); */
        		$.alert('内容不可为空！');
    			return false;
    		}
    		$.confirm({
    			title: '提示!',
    		    content: '确定提交？',
    		    type: 'blue',
    		    typeAnimated: true,
    		    buttons: {
    		    	确定: function () {
    		    		$("#SaveSubmit").html('<i class="fa fa-spinner fa-spin"></i>处理中...');
    		    		$('#SaveSubmit').prop('disabled',true);
    		    		$.ajax({
    		    			type:"post",
    		        		url:"${pageContext.request.contextPath}/Main/packageMan/packageSetSubmit.action",
    		        		//contentType:"application/json;charset=utf-8",
    		        		async: true,
    		        		data:"packagename="+packagename+"&packagenumber="+packagenumber+"&packageabs="+packageabs+"&packagesustime="+packagesustime+"&packageoperatetime="+packageoperatetime,
    		        		success:function(data){
    		        			$("#SaveSubmit").html('保存');
                		    	$('#SaveSubmit').prop('disabled',false);
    		        			$.alert(data.msg);
    		        		},
    		        		error:function(request){
    		        			$("#SaveSubmit").html('保存');
                		    	$('#SaveSubmit').prop('disabled',false);
    		        			$.alert("连接异常！");
    		        		}
    		    		});
    		        },
    		    	关闭: function () {},
    		    }
    		});
    	}
    	function num(obj){
        	obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
        	obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字
        	obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
        	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
        	obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
        }
    	function words_deal(id){
        	var value=$('#'+id).val().length;
	        if(value>150){
	        	var num=$('#'+id).val().substr(0,150);
	        	$('#'+id).val(num);
	        	//alert("超过字数限制，多出的字将被截断！" );
	        }
        }
    </script>
</body>
</html>